<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: RoleMan.php 320 2008-11-23 07:18:37Z steen.rabol@gmail.com $
 *
 */

class RoleMan extends PortalAdminPage
{
	protected function bindData()
	{
		$offset	= $this->PagesGrid->CurrentPageIndex*$this->PagesGrid->PageSize;
		$limit	= $this->PagesGrid->PageSize;
		$ds		= $this->DataAccess->createCommand("select * from tblroles LIMIT $offset,$limit")->query();

		$this->PagesGrid->DataSource		= $ds;
		$this->PagesGrid->VirtualItemCount	= count($ds);
		$this->PagesGrid->dataBind();
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		$this->setAdminPageTitle('Roles');

		if(!$this->IsPostBack)
		{
			$this->bindData();
		}
	}

	public function changePage($sender,$param)
	{
		$this->PagesGrid->CurrentPageIndex=$param->NewPageIndex;
		$this->bindData();
	}

	public function pagerCreated($sender,$param)
	{
		$param->Pager->Controls->insertAt(0,'Page: ');
	}

	public function editItem($sender,$param)
	{
		$this->PagesGrid->EditItemIndex=$param->Item->ItemIndex;
		$this->bindData();
	}

	public function saveItem($sender,$param)
	{
		$item		= $param->Item;
		$Id			= $this->PagesGrid->DataKeys[$item->ItemIndex];
		$name		= $item->RoleName->TextBox->Text;
		$this->DataAccess->createCommand("update tblroles set name='$name' where id=$Id")->execute();
		$this->gotoPage('Admin.RoleMan');
	}

	public function cancelItem($sender,$param)
	{
		$this->gotoPage('Admin.RoleMan');
	}

	public function deleteItem($sender,$param)
	{
		$item	= $param->Item;
		$Id		= $this->PagesGrid->DataKeys[$item->ItemIndex];
		$sql	= "delete from tblroles where id=$Id";
		$this->DataAccess->createCommand($sql)->execute();
		$this->gotoPage('Admin.RoleMan');
	}

	public function itemCreated($sender,$param)
	{
		$item=$param->Item;
		if($item->ItemType==='EditItem')
		{
			$item->RoleName->TextBox->Columns=45;
		}

		if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem')
		{
			// add an aleart dialog to delete buttons
			$item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'' . Prado::localize("Are you sure?") . '\')) return false;';
		}
	}
}
?>